<?php
/*
 * program:	均源
 * author:	雨中漫步 & 上善若水 & qhxin
 * email:	qhxin@qhxin.com
 * date:	2014/11/11
 * description:	又是一年双十一，不能剁手，就写点东西吧~~~~~~
 */

defined('IN_SCHOOL') or die();

/*{TranslateTagBegin}*/
class model_comm extends base_model{

	//hook mod_comm_start.php
	private $table;

	function __construct() {
		//hook mod_comm_init_init_before.php
		parent::__construct();
		$this->table = 'comm';
		//hook mod_comm_init_init_end.php
	}
	
	public function comm_get($cid) {
		//hook mod_comm_comm_get.php
		return $this->db->get($this->table.'-cid-'.$cid);
	}
	
	public function comm_del($fid) {
		//hook mod_comm_comm_del.php
		return $this->db->delete($this->table.'-fid-'.$fid);
	}

	public function comm_del_one($cid) {
		//hook mod_comm_comm_del_one.php
		return $this->db->delete($this->table.'-cid-'.$cid);
	}

	public function comm_add($fid = 0, $uid = 0, $content = '', $lc) {
		$cid = $this->db->maxid($this->table.'-cid', '+1');
		//hook mod_comm_comm_add.php
		return $this->db->set( $this->table.'-cid-'.$cid, 
					array(	'cid'=>$cid,'fid'=>$fid,'uid'=>$uid,
							'content'=>$content, 'lc'=>$lc));
	}

	public function comm_edit($cid , $str) {
		//hook mod_comm_comm_edit.php
		
		return $this->db->update( $this->table.'-cid-'.$cid,
				array('content'=>"$str") );
	}
	
	public function comm_edit_tj($cid , $met = '+',&$tid) {
		$arr = $this->db->get($this->table.'-cid-'.$cid);
		if(empty($arr))
			return false;
		$tid = $arr['fid'];
		$tj = ($met == '+') ? $arr['tj'] + 1 : $arr['tj'] - 1;
		//hook mod_comm_comm_edit_tj.php
		return $this->db->update( $this->table.'-cid-'.$cid, 
					array('tj'=> $tj));
	}
	
	public function comm_list($fid = 0, $start = 0, $limit = 0 ,$order = -1) {
		$ret = array();
		if($fid < 1)
			return $ret;
		$arr = $this->db->index_fetch($this->table , 'cid'
										, array('fid'=>$fid), array('cid'=> $order)
										, $start, $limit);
		
		//hook mod_comm_comm_list.php
		return $arr;
	}
	
	public function comm_of_users_list($uid, $start = 0, $limit = 0 ,$order = -1) {
		//hook mod_comm_comm_of_users_list.php
		$arr = $this->db->index_fetch($this->table , 'cid'
										, array('uid'=>$uid), array('cid'=> $order)
										, $start, $limit);
		return $arr;
	}
	
	public function comm_of_users_count($uid) {
		//hook mod_comm_comm_of_users_count.php
		return $this->db->index_count($this->table, array('uid'=>$uid));
	}

	//hook mod_comm_end.php
}
/*{TranslateTagEnd}*/

?>